home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / GE_VSRC.ZIP / POLY.ASM < prev    next >
Assembly Source File  |  1995-04-15  |  4KB  |  171 lines

  1. ;My polygon routines.
  2.  
  3.         .386p
  4. code32  segment para public use32
  5.         assume cs:code32, ds:code32
  6.  
  7. include pmode.inc
  8. public _ScanEdge, _DrawLineList
  9. ideal
  10. ;scan edge - scan converts a poly using a 16.16 fixed point line thing.
  11. ;entry - ax = x1, bx = y1, cx = x2, dx = y2, bp = ymin, edi -> list
  12. proc _ScanEdge
  13.     cmp dx,bx             
  14.     jz endscan
  15.     jg noswap             
  16.     
  17.     xchg dx,bx            ;make sure we're going downwards.
  18.     xchg ax,cx            
  19.  
  20. noswap:
  21.     neg bp                ;since bx is our starty, we calc address by
  22.     add bp,bx             ;4*y's to skip (i.e., our y - min y).
  23.     and ebp,0ffffh
  24.     shl ebp,2
  25.     add edi,ebp
  26. fillfirst:
  27.     push ax dx
  28.     sub cx,ax             
  29.     movzx eax,cx          ;ax = x2-x1
  30.     shl eax,16            ;get it to 16.16
  31.  
  32.     movzx ecx,dx          ;get y2
  33.     sub cx,bx             ;cx = y2-y1
  34.     cdq
  35.     idiv ecx              ;divide it.
  36.     mov ecx,eax           ;cx is the x step value (fractional).
  37.     pop dx ax
  38.  
  39.     and ax,0ffffh
  40.     shl eax,16            ;get x in fixed point too.
  41.  
  42.     add eax,ecx           ;skip first point.
  43.  
  44. nextpoint:
  45.     push edi
  46.     rol eax,16
  47.     cmp [word edi],-1
  48.     jz thisok
  49.     add edi,2       
  50. thisok:
  51.     mov [edi],ax          ;store integer part.
  52.     rol eax,16
  53.     add eax,ecx           
  54.     inc bx
  55.     pop edi
  56.     add edi,4
  57.     cmp bx,dx
  58.     jnz nextpoint
  59. endscan:
  60.     ret
  61. endp       
  62.  
  63.  
  64. ;Drawlinelist - draws every line in the list passed to it.
  65. ;Must be in increasing Y order, but order of endpoints doesn't matter.
  66. ;BP=YMin, ESI->list, CX = length, DL=Color, DI = video offset.
  67.  
  68. linecolor db 0
  69.  
  70. proc _DrawLineList
  71.  
  72.     mov [linecolor],dl
  73.     push di
  74.     movzx edi,bp
  75.     lea edi,[edi*2]
  76.     lea edi,[edi*8]
  77.     lea edi,[edi+edi*4]               ;80 * y
  78.     pop bp
  79.     and ebp,0ffffh
  80.     add edi,0a0000h
  81.     sub edi,[_code32a]
  82.     add edi,ebp
  83.     xor eax,eax
  84. drawall:    
  85.     push cx edi
  86.     lodsw                             ;get endpoints
  87.     mov bx,ax
  88.     lodsw   
  89.  
  90.     or ax,ax
  91.     js dontdraw
  92.  
  93.     cmp ax,bx
  94.     jl KeepOrder
  95.     
  96. ChangeOrder:
  97.     xchg ax,bx                        ;force ax<bx
  98. KeepOrder:  
  99.  
  100.     movzx ebp,ax
  101.     shr bp,2                          ;X Mod 4
  102.     add edi,ebp
  103.  
  104.     push bx                           ;ebp = length of line
  105.     neg bp
  106.     shr bx,2
  107.     add bp,bx
  108.     pop bx
  109.  
  110.     mov cl,al                         ;draw first byte
  111.     and cl,3
  112.     mov ax,0f02h
  113.     shl ah,cl
  114.     and ah,0fh
  115.     mov dx,3c4h
  116.  
  117.     dec ebp                           ;draw 1st, take it out.
  118.     js OneByte                        ;Is it < 4 pixels??
  119.  
  120.     out dx,ax                         ;set reg
  121.  
  122.     mov al,[linecolor]                ;write it.
  123.     stosb
  124.  
  125.     mov ax,0f02h                      ;middle bytes
  126.     out dx,ax
  127.     mov al,[linecolor]                ;setup for word writes.
  128.     mov ah,al
  129. _h1:
  130.     mov ecx,ebp                       ;This *might* be faster than
  131.     shr ecx,1                         ;a single rep stosb; I can't tell 
  132.     rep stosw                         ;on my machine (I get .008 ms dif)
  133.     adc cx,cx
  134.     rep stosb                         ;draw any remaining byte
  135. _h2:
  136.     mov cl,bl                         ;do the other stuff.
  137.     not cl
  138.     and cl,3
  139.     mov ax,0f02h
  140.     shr ah,cl                         ;get the mask.
  141.     out dx,ax
  142.     mov al,[linecolor]                ;draw it
  143.     stosb
  144. dontdraw:
  145.     pop edi cx
  146.     add edi,80
  147.     dec cx
  148.     jnz drawall
  149.     ret
  150.  
  151. OneByte:
  152.     mov cl,bl
  153.     not cl
  154.     and cl,3
  155.     mov bh,0fh
  156.     shr bh,cl
  157.     and ah,bh
  158.     out dx,ax
  159.     mov al,[linecolor]              
  160.     stosb
  161.     pop edi cx
  162.     add edi,80
  163.     dec cx
  164.     jnz drawall
  165.     ret
  166. endp
  167.  
  168. ends 
  169. end
  170.  
  171.